package storage.v1;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;

import com.onpositive.data.IPropertyConstants;
import com.onpositive.knowledge.model.IThing;
import com.onpositive.mediawiki.dataminer.MediaWikiUniverse;
import com.onpositive.mediawiki.dataminer.WikiThing;
import com.onpositive.mediawiki.propertyparser.PropertyCharacteristic;
import com.onpositive.semantic.model.api.meta.BaseMeta;
import com.onpositive.semantic.model.api.meta.IMeta;
import com.onpositive.semantic.model.api.property.IProperty;
import com.onpositive.units.ParsedLinkArray;
import com.onpositive.units.ParsedString;
import com.onpositive.units.ParsedValue;

public class ParentCategoriesProperty implements IProperty {
	
/**
	 * 
	 */
	private static final long serialVersionUID = -3732869246597181547L;

public static final String PROPERTY_NAME = "parent-categories-property-metadata" ;
	
	private BaseMeta meta ;
	private MediaWikiUniverse universe ;
	
	public ParentCategoriesProperty( MediaWikiUniverse universe  )
	{
		this.universe = universe ;
		meta = new BaseMeta() ;
		meta.putMeta( PropertyCharacteristic.CHAR_PARSER_ID_LABEL, ParsedLinkArray.ID ) ;
		meta.putMeta(PropertyCharacteristic.CHAR_PROPERTY_NAME_LABEL,PROPERTY_NAME );
		meta.putMeta(IPropertyConstants.CHAR_IS_SERVICE_PROPERTY, true );
	}

	@Override
	public IMeta getMeta() {

		return meta;
	}

	@Override
	public String getId() {

		return PROPERTY_NAME;
	}

	@Override
	public Object getValue(Object obj)
	{		
		if( !(obj instanceof WikiThing) )
			return null ;
		
		String id = ( (IThing) obj ).getId();
		Collection<String> list = universe.getParents(id) ;
			
		if( list == null )
			return null ;
		
		HashSet<ParsedValue> res = new HashSet<ParsedValue>() ;
		res.add( new ParsedLinkArray( new ArrayList( list ), "ParentCategoriesProperty" ) ) ;
		return res ;
	}

}
